package com.cedarhd.finance.log.domain.service;

import com.cedarhd.finance.log.domain.entity.ErrorLog;
import com.cedarhd.finance.log.domain.repository.ErrorLogRepository;
import com.cedarhd.finance.log.dto.ErrorLogDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/3/6.
 */
@Service
public class ErrorLogService {

    @Autowired
    private ErrorLogRepository errorLogRepository;

    public ErrorLogRepository getRepository(){
        return errorLogRepository;
    }

    /**
     * 保存日志
     * @param dto
     * @return
     */
    public ErrorLog add(ErrorLogDto dto){
        ErrorLog errorLog = new ErrorLog();
        errorLog.setCode(dto.getCode());
        errorLog.setUrgent(dto.getUrgent());
        errorLog.setShowDesc(dto.getShowDesc());
        errorLog.setSysDesc(dto.getSysDesc());
        return errorLogRepository.saveAndFlush(errorLog);
    }

    /**
     * 分页数据
     * @param errorLogPage
     * @return
     */
    public List<ErrorLog> coverErrorLogDTO(Page<ErrorLog> errorLogPage){
        List<ErrorLog> result = new ArrayList<>();
        for(ErrorLog errorLog : errorLogPage){
            result.add(errorLog);
        }
        return result;
    }
}
